From 93859a896b2f09eba829eb6ba1a718693d4bffeb Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Sun, 6 Nov 2005 17:50:24 +0100 Subject: [PATCH] Fix error path in blkback driver where a grant mapping in the middle of a batch fails. Spotted by Harry Butterworth (IBM). Signed-off-by: Keir Fraser --- .../drivers/xen/blkback/blkback.c | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c index 3dc929f0a7..d15c062695 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c @@ -340,7 +340,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) struct bio *bio = NULL, *biolist[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int nbio = 0; request_queue_t *q; - int ret; + int ret, errors = 0; /* Check that number of segments is sane. */ nseg = req->nr_segments; @@ -374,23 +374,23 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) BUG_ON(ret); for (i = 0; i < nseg; i++) { - if (unlikely(map[i].handle < 0)) { - DPRINTK("invalid buffer -- could not remap it\n"); - fast_flush_area(pending_idx, nseg); - goto bad_descriptor; + if (likely(map[i].handle >= 0)) { + pending_handle(pending_idx, i) = map[i].handle; + phys_to_machine_mapping[__pa(MMAP_VADDR( + pending_idx, i)) >> PAGE_SHIFT] = + FOREIGN_FRAME(map[i].dev_bus_addr>>PAGE_SHIFT); + fas = req->frame_and_sects[i]; + seg[i].buf = map[i].dev_bus_addr | + (blkif_first_sect(fas) << 9); + } else { + errors++; } - - phys_to_machine_mapping[__pa(MMAP_VADDR( - pending_idx, i)) >> PAGE_SHIFT] = - FOREIGN_FRAME(map[i].dev_bus_addr >> PAGE_SHIFT); - - pending_handle(pending_idx, i) = map[i].handle; } - for (i = 0; i < nseg; i++) { - fas = req->frame_and_sects[i]; - seg[i].buf = map[i].dev_bus_addr | - (blkif_first_sect(fas) << 9); + if (errors) { + DPRINTK("invalid buffer -- could not remap it\n"); + fast_flush_area(pending_idx, nseg); + goto bad_descriptor; } if (vbd_translate(&preq, blkif, operation) != 0) { -- 2.30.2